﻿@page "/app/mine"
@inherits AppPage

<div style="padding:50px 30px;text-align:center;">
    <Avatar Size="5rem" Src="@user?.AvatarUrl" />
    <div style="margin-top:10px;">@user?.Name (@user?.UserName)</div>
</div>
<div style="padding:20px;">
    <AppMenuList DataSource="items">
        <ListItem OnClick="()=>OnItemClick(context)">
            <div>
                <Icon Type="@context.Icon" />
                <span>@context.Name</span>
            </div>
            @if (!string.IsNullOrWhiteSpace(context.Url))
            {
                <Icon Type="right" />
            }
        </ListItem>
    </AppMenuList>
</div>
<div style="padding:20px;">
    <Button Type="@ButtonType.Primary" Danger Block OnClick="e=>Logout()">@Language["Nav.Exit"]</Button>
</div>

@code {
    private IAuthService authService;
    private UserInfo user;
    private List<MenuInfo> items = [];

    protected override async Task OnInitAsync()
    {
        await base.OnInitAsync();
        authService = await CreateServiceAsync<IAuthService>();

        user = CurrentUser;
        items.Add(new MenuInfo { Id = "Mobile", Name = user?.Mobile, Icon = "mobile" });
        items.Add(new MenuInfo { Id = "Email", Name = user?.Email, Icon = "inbox" });
        items.Add(new MenuInfo
        {
            Id = "Profile",
            Name = Language.GetString("Title.MyProfile"),
            Icon = "user",
            Url = "/profile/user",
            BackUrl = "/app/mine"
        });
        items.Add(new MenuInfo
        {
            Id = "Password",
            Name = Language.GetString("Title.SecuritySetting"),
            Icon = "lock",
            Url = "/profile/password",
            BackUrl = "/app/mine"
        });
    }

    private void OnItemClick(MenuInfo item)
    {
        if (string.IsNullOrWhiteSpace(item.Url))
            return;

        App.NavigateTo(item);
    }

    private void Logout()
    {
        UI.Confirm(Language["Tip.Exits"], App.SignOutAsync);
    }
}